package source;

/*
This file is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License version 2, 1991 as published by
the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
details.

A copy of the GNU General Public License can be found at:
http://www.gnu.org/licenses/gpl.html
*/
/**
*<p>Creates Global Graphics</p>
*/
public class GraphicsHandler{
	/**
	*<p>Holds information about a global graphic</p>
	*/
	public static int[] GFXspot = new int[5001];
	/**
	*<p>Holds information about a global graphic</p>
	*/
	public static int[] castID = new int[5001];
	/**
	*<p>Holds information about a global graphic</p>
	*/
	public static int[] moveID = new int[5001];
	/**
	*<p>Holds information about a global graphic</p>
	*/
	public static int[] endID = new int[5001];
	/**
	*<p>Holds information about a global graphic</p>
	*/
	public static int[] gfxX = new int[5001];
	/**
	*<p>Holds information about a global graphic</p>
	*/
	public static int[] gfxY = new int[5001];
	/**
	*<p>Holds information about a global graphic</p>
	*/
	public static int[] offX = new int[5001];
	/**
	*<p>Holds information about a global graphic</p>
	*/
	public static int[] offY = new int[5001];
	/**
	*<p>Holds information about a global graphic</p>
	*/
	public static int[] gfxA = new int[5001];
	/**
	*<p>Holds information about a global graphic</p>
	*/
	public static int[] gfxS = new int[5001];
	/**
	*<p>Holds information about a global graphic</p>
	*/
	public static int[] gfxSH = new int[5001];
	/**
	*<p>Holds information about a global graphic</p>
	*/
	public static int[] gfxFH = new int[5001];
	/**
	*<p>Holds information about a global graphic</p>
	*/
	public static int[] targetX = new int[5001];
	/**
	*<p>Holds information about a global graphic</p>
	*/
	public static int[] targetY = new int[5001];
	/**
	*<p>Holds information about a global graphic</p>
	*/
	public static int[] lockOn = new int[5001]; //5001
	/**
	*<p>Sets all the information about graphics to 0</p>
	*/
	public GraphicsHandler() {
		for (int i = 0; i <= 5000; i++){
			GFXspot[i] = 0;
			castID[i] = 0;
			moveID[i] = 0;
			endID[i] = 0;
			gfxX[i] = 0;
			gfxY[i] = 0;
			offX[i] = 0;
			offY[i] = 0;
			gfxA[i] = 0;
			gfxS[i] = 0;
			gfxSH[i] = 0;	
			gfxFH[i] = 0;
			targetX[i] = 0;
			targetY[i] = 0;
			lockOn[i] = 0; //-1
		}
	}
	/**
	*<p>Has a spell added</p>
	*@param castId int
	*@param casterY int
	*@param casterX int
	*@param offsetY int
	*@param offsetX int
	*@param angle int
	*@param speed int
	*@param movegfxID int
	*@param startHeight int
	*@param endHeight int
	*@param MageAttackIndex int
	*@param finishID int
	*@param enemyX int
	*@param enemyY int
	*/
	public static void addSpell(int castId, int casterY, int casterX, int offsetY, int offsetX, int angle, int speed, int movegfxID,int startHeight, int endHeight, int MageAttackIndex, int finishID, int enemyY, int enemyX) {
		for (int i = 0; i <= 5000; i++)
			if(GFXspot[i] == 0) { 
				GFXspot[i] = castId;
				castID[i] = castId;
				moveID[i] = movegfxID;
				endID[i] = finishID;
				gfxX[i] = casterX;
				gfxY[i] = casterY;
				offX[i] = offsetX;
				offY[i] = offsetY;
				gfxA[i] = angle;
				gfxS[i] = speed;
				gfxSH[i] = startHeight;
				gfxFH[i] = endHeight;
				targetX[i] = enemyX;
				targetY[i] = enemyY;
				lockOn[i] = MageAttackIndex;
				if (GFXspot[i] != -1)
					createSpell(castID[i], gfxY[i], gfxX[i], offY[i], offX[i], gfxA[i], gfxS[i], moveID[i], gfxSH[i], gfxFH[i], lockOn[i], endID[i], targetY[i], targetX[i]);
			}
	}
	/**
	*<p>Has a spell created for each player</p>
	*@param castId int
	*@param casterY int
	*@param casterX int
	*@param offsetY int
	*@param offsetX int
	*@param angle int
	*@param speed int
	*@param movegfxID int
	*@param startHeight int
	*@param endHeight int
	*@param MageAttackIndex int
	*@param finishID int
	*@param enemyX int
	*@param enemyY int
	*/
	public static void createSpell(int castId, int casterY, int casterX, int offsetY, int offsetX, int angle, int speed, int movegfxID,int startHeight, int endHeight, int MageAttackIndex, int finishID, int enemyY, int enemyX) {
	for (Player p : PlayerHandler.players) 
		if(p != null){ 
			client person = (client)p;
			if((person.playerName != null || person.playerName != "null"))
					person.firespell(castId, casterY, casterX, offsetY, offsetX, angle, speed, movegfxID, startHeight, endHeight, MageAttackIndex, finishID);
			}
	}
	/**
	*<p>Removes a graphic from the database</p>
	*@param castId int
	*@param enemyX int
	*@param enemyY int
	*/
	public static void removeGFX(int castId, int enemyX, int enemyY) {
		for (int i = 0; i <= 5000; i++)
			if(GFXspot[i] == castId && targetX[i] == enemyX && targetY[i] == enemyY) {
			GFXspot[i] = 0;
			castID[i] = 0;
			moveID[i] = 0;
			endID[i] = 0;
			gfxX[i] = 0;
			gfxY[i] = 0;
			offX[i] = 0;
			offY[i] = 0;
			gfxA[i] = 0;
			gfxS[i] = 0;
			gfxSH[i] = 0;
			gfxFH[i] = 0;
			targetX[i] = 0;
			targetY[i] = 0;
			lockOn[i] = 0; //-1
			}
	}
}